<?php

/**
 * @author Ta Van Chinh
 * @copyright 2013
 */

//function watermark_image($oldimage_name, $new_image_name)
//{
//   $image_path = "watermark.png";
//   list($owidth,$oheight) = getimagesize($oldimage_name);
//   $width = $height = 300; 
//   $im = imagecreatetruecolor($width, $height);
//   $img_src = imagecreatefromjpeg($oldimage_name);
//   imagecopyresampled($im, $img_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
//   $watermark = imagecreatefrompng($image_path);
//   list($w_width, $w_height) = getimagesize($image_path); 
//   $pos_x = $owidth - 5; 
//   $pos_y = $oheight -5;
//   imagecopy($im, $watermark, $pos_x, $pos_y, 0, 0, $w_width, $w_height);
//   imagejpeg($im, $new_image_name, 100);
//   imagedestroy($im);
//   //unlink($oldimage_name);
//   echo $pos_x.'-'.$pos_y;
//   return true;
//   
//}
//watermark_image('__DSC0713psd.jpg','new__DSC0713psd.jpg');
$stamp = imagecreatefrompng('watermark.png');
$im = imagecreatefromjpeg('test.png');

// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);

// Copy the stamp image onto our photo using the margin offsets and the photo 
// width to calculate positioning of the stamp. 
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
imagejpeg($im,'new.jpg');

?>